#ifndef  _T_SOCKET_SERVER_H_
#define  _T_SOCKET_SERVER_H_

#include "../define/define.h"
#include "tsocket.h"
#include "../util/log.h"

class tcp_thread;

class tcp_sink
{
public:
	virtual bool OnRead(uint32 socket, char* buf, uint32 buf_size) = 0;
	virtual bool OnError(uint32 socket) =0;
	virtual bool OnSend()=0;
	virtual bool OnAccept(uint32 socket, sockaddr sock_addr,uint16 port) = 0;
};

class tcp_server
{
public:
	
	tcp_server(tcp_sink* sink);
	~tcp_server();

	int sendbuf(uint32 socket, char* buf, uint32 buf_size);

	bool  del_socket(uint32 socket);
	bool  clear_socket(uint32 socket);
	
	bool  add_socket(uint16 port,uint32 socket);

	bool  add_port(uint16 port);
	bool  del_port(uint16 port);
	
private:

	std::map<uint16,t_socket_server*>  m_portmap;
	std::map<uint32,uint16>            m_socketmap;
	
	tcp_sink*        m_sink;
	tcp_thread*      m_thread;

	logfile*         m_log;
};

#endif
